// 递归
function inorderTraversal(root) {
  return root ? [...inorderTraversal(root.left), root.val, ...inorderTraversal(root.right)] : []
}

// 迭代，使用栈
function inorderTraversal(root) {
  let result = [], stack = [], cur = root
  while (cur !== null || stack.length !== 0) {
    if (cur !== null) {
      stack.push(cur)
      cur = cur.left
    } else {
      cur = stack.pop()
      result.push(cur.val)
      cur = cur.right
    }
  }
  return result
}